package se.sudoku;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;


public class SudokuTimeOut extends Activity {

	//SUDOKUMENU ITEMS
	private PopupWindow timeOut;
	private Button waitmenu_btn_1;
	private Activity activity;
	
	//constructor
	public SudokuTimeOut(Context c) {
		activity = (Activity) c;
		//popup window
		timeOut = new PopupWindow(View.inflate(c, R.layout.sudokutimeout, null), LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
		waitmenu_btn_1 = (Button)timeOut.getContentView().findViewById(R.id.timeout_tomain);
		waitmenu_btn_1.setOnClickListener(sudukoTimeOutListener);
	}
	
	//toggle windows
	public void toggleTimeOutWindow(){

		if(!timeOut.isShowing()){
			timeOut.showAtLocation(activity.findViewById(R.id.sudokuview), Gravity.CENTER, 0, 0);
    	}
    	else{
    		timeOut.dismiss();
    	}
    	
    }

	private OnClickListener sudukoTimeOutListener = new OnClickListener() {
		public void onClick(View v) {
			
			//to main menu
			if(v==waitmenu_btn_1){
				toggleTimeOutWindow();
				activity.setResult(RESULT_CANCELED);
				activity.finish();
			}
	    }
	};

}